package com.xinqi.modules.sys.complaint.controller.admin;

import com.xinqi.common.base.constants.ServiceNameConstants;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.enums.ComplaintConfigDisableFeatureEnum;
import com.xinqi.common.log.syslog.annotation.Log;
import com.xinqi.common.log.syslog.enums.BusinessType;
import com.xinqi.common.log.syslog.enums.OperatorType;
import com.xinqi.modules.sys.complaint.dto.req.ComplaintConfigCreateDTO;
import com.xinqi.modules.sys.complaint.dto.req.ComplaintConfigDeleteDTO;
import com.xinqi.modules.sys.complaint.dto.req.ComplaintConfigQueryDTO;
import com.xinqi.modules.sys.complaint.dto.req.ComplaintConfigUpdateDTO;
import com.xinqi.modules.sys.complaint.dto.rsp.ComplaintConfigResultDTO;
import com.xinqi.modules.sys.complaint.service.ComplaintConfigService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * ADMIN -- 用户投诉规则
 *
 * @author: yyzhenn
 * @date: 2023/04/23
 */
@Validated
@RestController
@RequestMapping("/admin/complaint-config")
@RequiredArgsConstructor
public class ComplaintConfigAdminController {
    private final ComplaintConfigService complaintConfigService;

    @Operation(summary = "禁用功能-枚举列表")
    @GetMapping("/disableFeature/list")
    public R<List<Map<String, String>>> disableFeatureList() {
        return R.data(ComplaintConfigDisableFeatureEnum.getSelectList());
    }

    @Operation(summary = "用户投诉规则-分页")
    @GetMapping("/page")
    public R<PageInfo<ComplaintConfigResultDTO>> page(@ParameterObject ComplaintConfigQueryDTO dto) {
        return R.data(complaintConfigService.page(dto, dto));
    }

    @Operation(summary = "用户投诉规则-列表")
    @GetMapping("/list")
    public R<List<ComplaintConfigResultDTO>> list(@ParameterObject ComplaintConfigQueryDTO dto) {
        return R.data(complaintConfigService.find(dto));
    }

    @Operation(summary = "用户投诉规则-详情")
    @GetMapping("/info/{id}")
    public R<ComplaintConfigResultDTO> info(@NotNull(message = "{complaint.config.id.not.blank}") @PathVariable("id") Long id) {
        return R.data(complaintConfigService.findById(id));
    }

    @Operation(summary = "用户投诉规则-新增")
    @PostMapping("/add")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 新增投诉规则", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    public R<Long> insert(@Validated @RequestBody ComplaintConfigCreateDTO dto) {
        return R.data(complaintConfigService.insert(dto));
    }

    @Operation(summary = "用户投诉规则-修改")
    @PostMapping("/edit")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 修改投诉规则", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R<Boolean> edit(@Validated @RequestBody ComplaintConfigUpdateDTO dto) {
        return R.data(complaintConfigService.updateById(dto));
    }

    @Operation(summary = "用户投诉规则-删除")
    @PostMapping("/remove")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 删除投诉规则", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R<Boolean> remove(@Validated @RequestBody ComplaintConfigDeleteDTO dto) {
        return R.data(complaintConfigService.deleteById(dto));
    }
}
